library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.std_logic_unsigned.all;

entity test_gen is
port (
	clk, rst, mode : in std_logic;
	tb_dataout, tb_key : out std_logic_vector(127 downto 0);
	tb_start : buffer std_logic;
	sel : std_logic_vector(1 downto 0)
);
end test_gen;

architecture Behavioral of test_gen is
	signal counter : std_logic_vector(34 downto 0);

begin
process (clk, rst) 
begin
	if (rst = '1') then
		counter <= (others => '0');
		tb_dataout <= (others => '0');
		tb_key <= (others => '0');
		tb_start <= '0';
	elsif (rising_edge(clk)) then
		if (counter < 27000) then
			counter <= counter + 1;
			tb_dataout <= (others => '0');
			tb_key <= (others => '0');
			tb_start <= '0';
		else
			if(mode = '1') then
				-- Testy kodera
				if (sel = "00") then
					-- Wektory testowe FIPS-197 (Appendix B)
					tb_dataout <= X"3243f6a8885a308d313198a2e0370734";
					tb_key <= X"2b7e151628aed2a6abf7158809cf4f3c";
					-- prawidlowy wynik: 3925841d02dc09fbdc118597196a0b32
				elsif (sel = "01") then
					-- Wektory testowe FIPS-197 (Appendix C)
					tb_dataout <= X"00112233445566778899aabbccddeeff";
					tb_key <= X"000102030405060708090a0b0c0d0e0f";
					-- prawidlowy wynik: 69c4e0d86a7b0430d8cdb78070b4c55a
				elsif (sel = "10") then
					tb_dataout <= X"ffeeddccbbaa99887766554433221100";
					tb_key <= X"00112233445566778899aabbccddeeff";
					-- prawidlowy wynik: 7221393918a24d7d0ee3f2223bfa5b35
				else 
					tb_dataout <= X"10011001100110011001100110011001";
					tb_key <= X"01100110011001100110011001100110";
					-- prawidlowy wynik: c70356c5806c9216ed3b10eb0e30e446
				end if;
			else
				-- Testy dekodera
				if (sel = "00") then
					-- Wektory testowe FIPS-197 (Appendix B)
					tb_dataout <= X"3925841d02dc09fbdc118597196a0b32";
					tb_key <= X"2b7e151628aed2a6abf7158809cf4f3c";
					-- prawidlowy wynik: 3243f6a8885a308d313198a2e0370734
				elsif (sel = "01") then
					-- Wektory testowe FIPS-197 (Appendix C)
					tb_dataout <= X"69c4e0d86a7b0430d8cdb78070b4c55a";
					tb_key <= X"000102030405060708090a0b0c0d0e0f";
					-- prawidlowy wynik: 00112233445566778899aabbccddeeff
				elsif (sel = "10") then
					tb_dataout <= X"7221393918a24d7d0ee3f2223bfa5b35";
					tb_key <= X"00112233445566778899aabbccddeeff";
					-- prawidlowy wynik: ffeeddccbbaa99887766554433221100
				else 
					tb_dataout <= X"c70356c5806c9216ed3b10eb0e30e446";
					tb_key <= X"01100110011001100110011001100110";
					-- prawidlowy wynik: 10011001100110011001100110011001
				end if;
			end if;
			
			tb_start <= '1';
		end if;
	end if;
end process;

end Behavioral;
